package com.study.d2_reflect;

import org.junit.Test;

import java.lang.reflect.Method;

//目标：掌握获取类的成员方法
public class Test4Method {
    @Test
    public void testGetAllMethods() throws Exception {
        Class<Student> studentClass = Student.class;

        //获取类的全部成员方法
        Method[] methods = studentClass.getDeclaredMethods();
        for (Method method : methods) {
            System.out.println(method.getName()+" "+method.getParameterCount());
        }

        //定位单个方法
        Method m1 = studentClass.getDeclaredMethod("eat");
        Method m2 = studentClass.getDeclaredMethod("eat", String.class);

        Student s = new Student();
        m1.invoke(s);

        Object result = m2.invoke(s, "520");
        System.out.println(result);
    }
}
